<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="全库唯一码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'puid', validatorRules.puid]" placeholder="请输入全库唯一码"></a-input>
        </a-form-item>
        <a-form-item label="采购方总部编码   国网:SGCC/南网：CSG/其他：QT" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserhqcode', validatorRules.purchaserhqcode]" placeholder="请输入采购方总部编码   国网:SGCC/南网：CSG/其他：QT"></a-input>
        </a-form-item>
        <a-form-item label="供应商工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierworkno', validatorRules.supplierworkno]" placeholder="请输入供应商工单编号"></a-input>
        </a-form-item>
        <a-form-item label="国网侧供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliercode', validatorRules.suppliercode]" placeholder="请输入国网侧供应商编码"></a-input>
        </a-form-item>
        <a-form-item label="供应商名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliername', validatorRules.suppliername]" placeholder="请输入供应商名称"></a-input>
        </a-form-item>
        <a-form-item label="采集规范版本号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'standardversion', validatorRules.standardversion]" placeholder="请输入采集规范版本号"></a-input>
        </a-form-item>
        <a-form-item label="规格型号编码  默认，组合电器：gis596267/断路器：breaker478920" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'modelcode', validatorRules.modelcode]" placeholder="请输入规格型号编码  默认，组合电器：gis596267/断路器：breaker478920"></a-input>
        </a-form-item>
        <a-form-item label="物资品类类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categorytype', validatorRules.categorytype]" placeholder="请输入物资品类类型"></a-input>
        </a-form-item>
        <a-form-item label="厂区编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'factorycode', validatorRules.factorycode]" placeholder="请输入厂区编号"></a-input>
        </a-form-item>
        <a-form-item label="供应商数据编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'suppliersupportid', validatorRules.suppliersupportid]" placeholder="请输入供应商数据编号"></a-input>
        </a-form-item>
        <a-form-item label="供应商产品厂内编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productmodel', validatorRules.productmodel]" placeholder="请输入供应商产品厂内编码"></a-input>
        </a-form-item>
        <a-form-item label="生产设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentname', validatorRules.equipmentname]" placeholder="请输入生产设备名称"></a-input>
        </a-form-item>
        <a-form-item label="生产设备唯一识别号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'equipmentuniquecode', validatorRules.equipmentuniquecode]" placeholder="请输入生产设备唯一识别号"></a-input>
        </a-form-item>
        <a-form-item label="感知过程" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'processtype', validatorRules.processtype]" placeholder="请输入感知过程"></a-input>
        </a-form-item>
        <a-form-item label="波头时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'waveheadtime', validatorRules.waveheadtime]" placeholder="请输入波头时间" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="波尾时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'waveendtime', validatorRules.waveendtime]" placeholder="请输入波尾时间" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="峰值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'paekvalue', validatorRules.paekvalue]" placeholder="请输入峰值" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="波形数据" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'waveform', validatorRules.waveform]" placeholder="请输入波形数据"></a-input>
        </a-form-item>
        <a-form-item label="采集时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择采集时间" v-decorator="[ 'checktime', validatorRules.checktime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="工序" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'pdcode', validatorRules.pdcode]" placeholder="请输入工序"></a-input>
        </a-form-item>
        <a-form-item label="状态表示" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入状态表示"></a-input>
        </a-form-item>
        <a-form-item label="错误信息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息"></a-input>
        </a-form-item>
        <a-form-item label="insertdate" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'insertdate', validatorRules.insertdate]" placeholder="请输入insertdate"></a-input>
        </a-form-item>
        <a-form-item label="remarkone" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remarkone', validatorRules.remarkone]" placeholder="请输入remarkone"></a-input>
        </a-form-item>
        <a-form-item label="remarktwo" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remarktwo', validatorRules.remarktwo]" placeholder="请输入remarktwo"></a-input>
        </a-form-item>
        <a-form-item label="remarkthree" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remarkthree', validatorRules.remarkthree]" placeholder="请输入remarkthree"></a-input>
        </a-form-item>
        <a-form-item label="remarkfour" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remarkfour', validatorRules.remarkfour]" placeholder="请输入remarkfour"></a-input>
        </a-form-item>
        <a-form-item label="remarkfive" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'remarkfive', validatorRules.remarkfive]" placeholder="请输入remarkfive"></a-input>
        </a-form-item>
        
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "EipLightningImpulseModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        puid:{rules: [{ required: true, message: '请输入全库唯一码!' }]},
        purchaserhqcode:{},
        supplierworkno:{rules: [{ required: true, message: '请输入供应商工单编号!' }]},
        suppliercode:{rules: [{ required: true, message: '请输入国网侧供应商编码!' }]},
        suppliername:{},
        standardversion:{},
        modelcode:{},
        categorytype:{rules: [{ required: true, message: '请输入物资品类类型!' }]},
        factorycode:{},
        suppliersupportid:{},
        productmodel:{},
        equipmentname:{},
        equipmentuniquecode:{},
        processtype:{},
        waveheadtime:{rules: [{ required: true, message: '请输入波头时间!' }]},
        waveendtime:{rules: [{ required: true, message: '请输入波尾时间!' }]},
        paekvalue:{rules: [{ required: true, message: '请输入峰值!' }]},
        waveform:{},
        checktime:{rules: [{ required: true, message: '请输入采集时间!' }]},
        pdcode:{},
        ioflag:{},
        message:{},
        insertdate:{},
        remarkone:{},
        remarktwo:{},
        remarkthree:{},
        remarkfour:{},
        remarkfive:{},
        },
        url: {
          add: "/pg/eipLightningImpulse/add",
          edit: "/pg/eipLightningImpulse/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'puid','purchaserhqcode','supplierworkno','suppliercode','suppliername','standardversion','modelcode','categorytype','factorycode','suppliersupportid','productmodel','equipmentname','equipmentuniquecode','processtype','waveheadtime','waveendtime','paekvalue','waveform','checktime','pdcode','ioflag','message','insertdate','remarkone','remarktwo','remarkthree','remarkfour','remarkfive'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'puid','purchaserhqcode','supplierworkno','suppliercode','suppliername','standardversion','modelcode','categorytype','factorycode','suppliersupportid','productmodel','equipmentname','equipmentuniquecode','processtype','waveheadtime','waveendtime','paekvalue','waveform','checktime','pdcode','ioflag','message','insertdate','remarkone','remarktwo','remarkthree','remarkfour','remarkfive'))
      }
      
    }
  }
</script>